package com.loong.seller.controller.forehead;

import com.loong.common.mvc.BaseForeheadController;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonInsert;
import com.loong.common.validator.group.CommonValidate;
import com.loong.global.dto.UserDTO;
import com.loong.seller.common.forehead.param.UserShopCollectionPageQueryParam;
import com.loong.seller.common.forehead.param.UserShopCollectionParam;
import com.loong.seller.common.forehead.param.UserShopCollectionQueryParam;
import com.loong.seller.handler.UserShopCollectionHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description:
 * @Author: hzp
 * @Date: 2021-1-6 15:08
 */
@RestController
@RequestMapping("/forehead/seller/userShopCollection")
public class UserShopCollectionController extends BaseForeheadController {
    @Resource
    private UserShopCollectionHandler userShopCollectionHandler;



    /**
     * 收藏店铺
     * @param param param
     * @return
     */
    @PostMapping("save")
    public Result save(@RequestBody @Validated(value = {CommonInsert.class}) UserShopCollectionParam param){
        param.setId(null);
        UserDTO userDTO = getUserDTO();
        param.setUserId(userDTO.getId());
        return handlerExecutor.execute(()->userShopCollectionHandler.save(param));
    }

    /**
     * 取消收藏
     * @param param param 批量取消
     * @return
     */
    @PostMapping("delete")
    public Result delete(@RequestBody @Validated(value = {CommonValidate.class})UserShopCollectionParam param){
        UserDTO userDTO = getUserDTO();
        return handlerExecutor.execute(()->userShopCollectionHandler.delete(userDTO.getId(),param.getShopIdList()));

    }

//    /**
//     * 批量删除
//     * @param param idList id集合
//     * @return
//     */
//    @PostMapping("batchDelete")
//    public Result batchDelete(@RequestBody UserShopCollectionParam param){
//        return handlerExecutor.execute(()->userShopCollectionHandler.batchDelete(param.getIdList()));
//    }

    /**
     * 检查用户是否收藏店铺
     * @param param
     * @return
     */
    @PostMapping("checkSelectShop")
    public Result checkSelectShop(@RequestBody @Validated(value = {CommonValidate.class})UserShopCollectionQueryParam param){
        UserDTO userDTO = getUserDTO();
        return handlerExecutor.execute(()->userShopCollectionHandler.findOne(userDTO.getId(),param.getShopId()));

    }

    /**
     * 分页查询用户收藏
     * @param param param
     * @return
     */
    @PostMapping("pageQuery")
    public Result pageQuery(@RequestBody @Validated(value = {CommonValidate.class}) UserShopCollectionPageQueryParam param){
        UserDTO userDTO = getUserDTO();
        return handlerExecutor.execute(()->userShopCollectionHandler.pageQuery(param,userDTO.getId()));

    }




}
